package seeders

import (
	"golang.org/x/crypto/bcrypt"

	"hyper/app/Models"
	"hyper/supports/database"
)

// 添加管理员
func AdminSeeder() {
	password, _ := bcrypt.GenerateFromPassword([]byte("123456"), bcrypt.DefaultCost)
	_admin := []Models.Admin{
		{
			CreateId: 0,
			Email:    "1@qq.com",
			Contact:  "jybtx",
			Password: string(password),
			Is_2fa:   1,
			Status:   3,
		},
		{
			CreateId: 0,
			Email:    "2@qq.com",
			Contact:  "Timi",
			Password: string(password),
			Is_2fa:   1,
			Status:   3,
		},
		{
			CreateId: 0,
			Email:    "3@qq.com",
			Contact:  "joy",
			Password: string(password),
			Is_2fa:   1,
			Status:   3,
		},
		{
			CreateId: 0,
			Email:    "4@qq.com",
			Contact:  "Lili",
			Password: string(password),
			Is_2fa:   1,
			Status:   3,
		},
	}
	if !isAdminExist() {
		database.DB.Create(&_admin)
	}
}

// 查找数据
func isAdminExist() bool {
	var count int64
	database.DB.Model(&Models.Admin{}).Count(&count)
	return count > 0
}
